SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--Процедура довавления в таблицу Список требований и Требование к работе
CREATE PROC [dbo].[PListReqANDReqWorkINSERT]
@Years NUMERIC(4,0),
@Ik_upContent INT,
@Ik_RefReq INT, 
@Expdoc Varchar(30)
AS
DECLARE @Temp INT;
SET @Temp=(select Ik_ReqWork from  ReqWork WHERE ik_upContent=@ik_upContent AND @Years=Years);
  IF(@Temp is NULL)
    BEGIN
     EXEC PReqWorkINSERT @Years,@ik_upContent;
     SET @Temp=@@IDENTITY; 	
INSERT INTO ListReq
(Ik_RefReq, Ik_ReqWork, Expdoc)
VALUES
(@Ik_RefReq, @Temp, @Expdoc)
END
  ELSE 
INSERT INTO ListReq
(Ik_RefReq, Ik_ReqWork, Expdoc)
VALUES
(@Ik_RefReq, @Temp, @Expdoc)
GO
